/**
 * @(#)ApkConfigController.java 2016年12月1日
 * Copyright(C) 2016 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.domian.MiguMusicRetentAddConfig;
import org.jsbd.boss.domian.MiguMusicRetentAddStatistics;
import org.jsbd.boss.service.IMiguMusicRetentAddConfigService;
import org.jsbd.boss.service.IMiguMusicRetentAddStatisticsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/miguMusicRetentAddConfig")
public class MiguMusicRetentAddConfigController {

	public static final Logger LOGGER = LoggerFactory.getLogger(MiguMusicRetentAddConfigController.class);

	@Resource
	private IMiguMusicRetentAddConfigService miguMusicRetentAddConfigService;

	@Resource
	private IMiguMusicRetentAddStatisticsService miguMusicRetentAddStatisticsService;

	@RequestMapping(value = "configList", method = RequestMethod.GET)
	public String configList() {
		return "/miguMusicRetentAddConfig/configList";
	}

	@RequestMapping(value = "getList")
	@ResponseBody
	public Map<String, Object> getList(Integer miguMusicId) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (miguMusicId != null) {
			MiguMusicRetentAddConfig miguMusicRetentAddConfig = new MiguMusicRetentAddConfig();
			miguMusicRetentAddConfig.setMiguMusicId(miguMusicId);
			List<MiguMusicRetentAddConfig> list = miguMusicRetentAddConfigService.getList(miguMusicRetentAddConfig);
			map.put("rows", list);
			map.put("total", 0);
		} else {
			List<MiguMusicRetentAddConfig> list = new ArrayList<>();
			list.add(new MiguMusicRetentAddConfig());
			map.put("rows", null);
			map.put("total", 0);
		}
		return map;
	}

	@RequestMapping(value = "/saveConfig")
	public void saveRetent(@RequestBody MiguMusicRetentAddConfig[] list, HttpServletResponse response) {

		if (list != null && list.length > 0) {
			Integer miguMusicId = list[0].getMiguMusicId();
			miguMusicRetentAddConfigService.deleteByMiguMusicId(miguMusicId);
		}
		miguMusicRetentAddConfigService.save(Arrays.asList(list));
		ResponseUtils.responseSuccess(response);
	}

	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public void delete(Integer[] ids, HttpServletResponse response) {
		try {
			List<Integer> list = Arrays.asList(ids);
			miguMusicRetentAddConfigService.delete(list);
			ResponseUtils.responseSuccess(response);
		} catch (Exception e) {
			ResponseUtils.responseFailure(response);
		}
	}

	@RequestMapping(value = "list", method = RequestMethod.GET)
	public String list() {
		return "/miguMusicRetentAddConfig/list";
	}
	
	@RequestMapping(value = "getListPage")
	@ResponseBody
	public Map<String, Object> getListPage(DataGridModel page,
			MiguMusicRetentAddStatistics miguMusicRetentAddStatistics) {
		return miguMusicRetentAddStatisticsService.getListPage(page, miguMusicRetentAddStatistics);
	}

	@RequestMapping(value = "listDay", method = RequestMethod.GET)
	public String listDay() {
		return "/miguMusicRetentAddConfig/listDay";
	}
	
	@RequestMapping(value = "getDayListPage")
	@ResponseBody
	public Map<String, Object> getDayListPage(DataGridModel page,
			MiguMusicRetentAddStatistics miguMusicRetentAddStatistics) {
		return miguMusicRetentAddStatisticsService.getDayListPage(page, miguMusicRetentAddStatistics);
	}

}
